package org.systm.adminuser.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
@RequestMapping("/admin/code")
public class CaptchaController {
    @GetMapping("/get/{time}")
    public void get(HttpServletResponse response,
                    HttpSession httpSession,
                    @PathVariable String time) throws IOException {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(100, 40, 4,35);
        httpSession.setAttribute("captchaTime", lineCaptcha.getCode());
        lineCaptcha.write(response.getOutputStream());
    }
}
